package cn.gson.crm.control;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sun.org.apache.regexp.internal.recompile;

import cn.gson.crm.model.pojo.ServiceType;
import cn.gson.crm.model.pojo.ServiceWay;
import cn.gson.crm.model.pojoVo.LLJ_CustomRecordVo;
import cn.gson.crm.service.LLJ_customerService;   

@Controller
public class LLJ_customerServiceControl {
	@Autowired
	private LLJ_customerService LLJ_customerService;
	
	
	
	@RequestMapping("/toCustomerService")
	public String toCustomerService(){
		return "llj/CustomerService";
	}       
	/* 查询客户服务信息   */
	@RequestMapping("/findAllcustomerService")
	@ResponseBody
	public List<LLJ_CustomRecordVo> findAllcustomerService(){
		try {
			return LLJ_customerService.findAllCustomerMessage();
		} catch (Exception e) {
			e.printStackTrace();  
			return null;     
		}
	}
	
	/* 添加客户服务记录    */
	@PostMapping("/addCusomerService")
	@ResponseBody
	public String addCusomerService(LLJ_CustomRecordVo CustomRecordVo){
		System.out.println("输出添加的客户记录："+CustomRecordVo);
		boolean juged=false;
		try {
			juged=LLJ_customerService.addCustomerService(CustomRecordVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(juged){
			return "success";
		}else{
			return "failed";
		}
	}
	
	/* 初始化客户服务记录   */
	@GetMapping("/searchCusomerMessage")
	@ResponseBody  
	public LLJ_CustomRecordVo searchCusomerMessage(Long crId){
		return LLJ_customerService.initedMessage(crId); 
	}
	/*  编辑客服服务 记录   */
	@PostMapping("/editCusmerMessage")
	@ResponseBody
	public String editCusmerMessage(LLJ_CustomRecordVo Rvo) throws Exception{
		System.out.println("1111111111111111111111111111111111111111");
		if(LLJ_customerService.editCustomerMessage(Rvo)){
			return "success";
		}else{
			return "failed";
		}
	}  
	/*  删除一条客服记录    */
	@GetMapping("/deleteCusmerMessage")
	@ResponseBody
	public String deleteCusmerMessage(Long crId){   
		String judge="failed";
		try {
			if(LLJ_customerService.deleteOneData(crId)){
				return "success";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return judge;  
  	}
	
	/*  批量删除     */
	@GetMapping("/deleteMoreData")
	@ResponseBody   
	public String deleteMoreData(String strIds) throws Exception{
		String judge="failed";
		String[] id=strIds.split(",");       
		
		try {
			for(int i=0;i<id.length;i++){
				System.out.println("输出："+id[i]);
				Long deleteId=(long) Integer.parseInt(id[i]);
				LLJ_customerService.deleteOneData(deleteId);
			}     
			judge="success";
		} catch (Exception e) {
			throw new Exception(e);    
		} 
		return judge; 
	}
	
	
	/*   根据客户服务主题查询模糊      */
	@GetMapping("/searchByTheme")
	@ResponseBody
	public List<LLJ_CustomRecordVo> searchByTheme(){
		
		return null; 
	}
	
	
	/*  查询服务类型    */
	@RequestMapping("/findServiceType")
	@ResponseBody
	public List<ServiceType> findServiceType(){
		
		return null;
	}
	
	/*  查询服务方式    */
	@RequestMapping("/findServiceWay")
	@ResponseBody
	public List<ServiceWay> findServiceWay(){
		  
		return null;
		
	}
	
	
	
}
